﻿using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using AppFramework.DinosaursParkMes.BOM;
using AppFramework.DinosaursParkMes.CodingRuleModel;
using AppFramework.DinosaursParkMes.DataBoard.Dto;
using AppFramework.DinosaursParkMes.Product;
using AppFramework.DinosaursParkMes.ReportForWork;
using AppFramework.DinosaursParkMes.ReportForWorker;
using AppFramework.DinosaursParkMes.TicketTask;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppFramework.DinosaursParkMes.DataBoard
{
    public class DataBoardService : AppFrameworkAppServiceBase, IDataBoardService
    {
        private readonly IRepository<ReportOfWorker> _rowRepository;
        private readonly IRepository<ProductWorkModels> _workRepository;
        private readonly IRepository<Productinfo> _productRepository;
        private readonly IRepository<TicketTaskinfo> _taskRepository;
        private readonly IRepository<QualityTesting> _testRepository;
        public DataBoardService(IRepository<ReportOfWorker> rowRepository, IRepository<ProductWorkModels> workRepository, IRepository<Productinfo> productRepository, IRepository<TicketTaskinfo> taskRepository = null, IRepository<QualityTesting> testRepository = null)
        {
            _rowRepository = rowRepository;
            _workRepository = workRepository;
            _productRepository = productRepository;
            _taskRepository = taskRepository;
            _testRepository = testRepository;
        }
        [HttpGet]

         public async  Task<List<ReportOfWorkerOutputDTO>> GetProductList ()
        {
      
  
            var list = from d in _rowRepository.GetAll()
                       join y in _testRepository.GetAll()
                       on d.ReportWorkerNumber equals y.ReportWorkerNumber
                       select new ReportOfWorkerOutputDTO
                       {
                           CreateTime = d.CreationTime.ToString("yyyy-MM-dd"),
                           ProductName = _workRepository.GetAll().Where(x => x.WorkOrderNumber == d.WorkNumber).FirstOrDefault().ProductName,
                           OrderCount = _taskRepository.GetAll().Count(),
                           ProjectCount = _productRepository.GetAll().Count(),
                           QualifiedQuantity=y.QualifiedQuantity,
                            QualityInspectionQuantity=y.QualityInspectionQuantity,
                            WorkCount=  _testRepository.GetAll().Count(),
                       };

            return list.ToList();
        }
    }
}
